if(typeof CrmAdsRetargeting==="undefined"){CrmAdsRetargeting=function(e){this.containerId=e.containerId||"crm-robot-ads-container-"+e.provider.TYPE;this.provider=e.provider;this.context=e.context;this.onRequest=e.onRequest;this.componentName=e.componentName;this.signedParameters=e.signedParameters;this.mess=e.mess;this.messageCode=e.messageCode;this.multiClients=!!e.multiClients;if(e.destroyEventName){BX.addCustomEvent(window,e.destroyEventName,BX.proxy((function(){this.unbindAll();this.cleanInstances()}),this))}this.clientId=e.clientId;this.accountId=e.accountId;this.audienceId=e.audienceId;this.audienceRegion=e.audienceRegion;this.autoRemoveDayNumber=e.autoRemoveDayNumber;this.audienceLookalikeMode=e.audienceLookalikeMode;this.isSupportCreateLookalikeFromSegments=e.isSupportCreateLookalikeFromSegments;this.hasAudiences=false;this.loaded=[];if(this.multiClients&&!this.clientId&&!this.provider.PROFILE){for(var t=0;t<this.provider.CLIENTS.length;t++){this.setProfile(this.provider.CLIENTS[t]);break}}this.init();this.showBlockByAuth();this.entityTitleNode=e.titleNodeSelector?document.querySelector(e.titleNodeSelector):null};CrmAdsRetargeting.prototype={instances:[],cleanInstances:function(){for(var e=0,t=this.instances.length;e<t;e++){if(!this.instances[e]){continue}this.instances[e].unbindAll();delete this.instances[e];this.instances[e]=null}},unbindAll:function(){BX.removeCustomEvent(window,"seo-client-auth-result",BX.proxy(this.onSeoAuth,this))},init:function(){this.cleanInstances();this.instances.push(this);this.containerNode=BX(this.containerId);if(!this.containerNode){this.containerNode=BX.create("div");this.containerNode.id=this.containerId}this.insertTemplateIntoNode("settings",this.containerNode);this.uiNodes={avatar:this.containerNode.querySelector("[data-bx-ads-auth-avatar]"),name:this.containerNode.querySelector("[data-bx-ads-auth-name]"),link:this.containerNode.querySelector("[data-bx-ads-auth-link]"),logout:this.containerNode.querySelector("[data-bx-ads-auth-logout]"),clientBlock:this.containerNode.querySelector("[data-bx-ads-client]"),clientInput:this.containerNode.querySelector("[data-bx-ads-client-input]"),account:this.containerNode.querySelector("[data-bx-ads-account]"),accountLoader:this.containerNode.querySelector("[data-bx-ads-account-loader]"),audience:[],errorNotFound:this.containerNode.querySelector("[data-bx-ads-audience-not-found]"),refreshButton:this.containerNode.querySelector("[data-bx-ads-refresh-btn]"),createLinks:BX.convert.nodeListToArray(this.containerNode.querySelectorAll("[data-bx-ads-audience-create-link]")),autoRemover:{node:this.containerNode.querySelector("[data-bx-ads-audience-auto-remove]"),checker:this.containerNode.querySelector("[data-bx-ads-audience-auto-remove-checker]"),select:this.containerNode.querySelector("[data-bx-ads-audience-auto-remove-select]")},addClientBtn:this.containerNode.querySelector("[data-bx-ads-client-add-btn]"),addAudienceBtn:this.containerNode.querySelector("[data-bx-ads-audience-add]"),regionInput:this.containerNode.querySelector("[data-bx-ads-region]"),regionLoader:this.containerNode.querySelector("[data-bx-ads-region-loader]"),audienceSelectorBtn:this.containerNode.querySelector("#audience-selector-btn"),audienceSelectorValue:this.containerNode.querySelector("#audience-selector-value")};const e=200;this.audienceSelectorBtn=new BX.UI.Button({color:BX.UI.Button.Color.LIGHT_BORDER,tag:BX.UI.ButtonTag.DIV,onclick:this.onAudienceSelectorBtnClick.bind(this),maxWidth:420});this.audienceSelectorBtn.renderTo(this.uiNodes.audienceSelectorBtn);BX.Dom.style(this.audienceSelectorBtn.getContainer(),{"min-width":`${e}px`});this.audienceMenu=this.generateAudienceMenu();this.uiNodes.createLinks.forEach((function(e){BX.bind(e,"click",BX.proxy((function(){if(!this.hasAudiences){this.showBlockRefresh()}}),this))}),this);BX.bind(this.uiNodes.refreshButton,"click",BX.proxy((function(){this.getProvider()}),this));if(this.uiNodes.autoRemover.checker){BX.bind(this.uiNodes.autoRemover.checker,"click",BX.proxy((function(){var e=this.uiNodes.autoRemover;e.select.disabled=!e.checker.checked}),this))}this.loader.init(this);BX.bind(this.uiNodes.logout,"click",BX.proxy((function(){this.logout(this.clientId)}),this));BX.bind(this.uiNodes.addAudienceBtn,"click",BX.proxy((function(){this.addAudience(this.uiNodes.account.value)}),this));BX.bind(this.uiNodes.addClientBtn,"click",BX.proxy((function(){BX.Seo.Ads.LoginFactory.getLoginObject(this.provider).login()}),this));this.listenSeoAuth();if(this.multiClients){if(this.clientSelector){this.clientSelector.destroy()}var t=this;this.clientSelector=new BX.Seo.Ads.ClientSelector(this.uiNodes.clientBlock,{selected:this.provider.PROFILE,items:this.provider.CLIENTS,canAddItems:true,events:{onNewItem:function(){BX.Seo.Ads.LoginFactory.getLoginObject(t.provider).login()},onSelectItem:function(e){t.setProfile(e)},onRemoveItem:function(e){t.logout(e.CLIENT_ID)}}})}BX.UI.Hint.init(this.containerNode)},showBlockByAuth:function(){if(this.provider.HAS_AUTH){this.showBlockMain()}else{this.showBlockLogin()}},listenSeoAuth:function(){BX.addCustomEvent(window,"seo-client-auth-result",BX.proxy(this.onSeoAuth,this))},onSeoAuth:function(e){e.reload=false;this.getProvider(e.clientId)},logout:function(e){var t=!(this.provider.TYPE==="facebook"||this.provider.TYPE==="instagram")?{}:{connect:"FBE",action:"disconnect",type:"disconnect"};this.showBlock("loading");this.request("logout",{logoutClientId:e},BX.delegate((function(e){this.provider=e;if(this.clientSelector){this.clientSelector.setSelected(this.provider.PROFILE);this.clientSelector.setItems(this.provider.CLIENTS)}this.showBlockByAuth()}),this),t)},addAudience:function(e){var t=this.entityTitleNode?this.entityTitleNode.value:"";this.showNewAudiencePopup(e,t)},getProvider:function(e){this.showBlock("loading");this.request("getProvider",{},BX.delegate((function(t){this.provider=t;if(this.clientSelector){if(!this.provider.PROFILE||e&&e!=this.provider.PROFILE.CLIENT_ID){for(var i=0;i<this.provider.CLIENTS.length;i++){var n=this.provider.CLIENTS[i];if(!e||e==n.CLIENT_ID){this.setProfile(n);break}}}this.clientSelector.setSelected(this.provider.PROFILE);this.clientSelector.setItems(this.provider.CLIENTS)}this.showBlockByAuth()}),this))},showBlock:function(e){e=BX.type.isArray(e)?e:[e];var t="data-bx-ads-block";var i=this.containerNode.querySelectorAll("["+t+"]");i=BX.convert.nodeListToArray(i);i.forEach((function(i){var n=i.getAttribute(t);var o=BX.util.in_array(n,e);i.style.display=o?"block":"none"}),this)},showBlockRefresh:function(){this.showBlock(["auth","refresh"])},showBlockLogin:function(){this.showBlock("login");var e=BX("seo-ads-login-btn");if(e&&this.provider&&this.provider.AUTH_URL){BX.bind(e,"click",BX.proxy((function(){BX.Seo.Ads.LoginFactory.getLoginObject(this.provider).login()}),this))}if(this.uiNodes.clientInput){this.uiNodes.clientInput.value=""}},showBlockMain:function(){if(this.uiNodes.avatar){this.uiNodes.avatar.style["background-image"]="url("+this.provider.PROFILE.PICTURE+")"}if(this.uiNodes.name){this.uiNodes.name.innerText=this.provider.PROFILE.NAME}if(this.uiNodes.link){if(this.provider.PROFILE.LINK){this.uiNodes.link.setAttribute("href",this.provider.PROFILE.LINK)}else{this.uiNodes.link.removeAttribute("href")}}if(this.uiNodes.clientInput){this.uiNodes.clientInput.value=this.provider.PROFILE&&this.provider.PROFILE.CLIENT_ID?this.provider.PROFILE.CLIENT_ID:""}this.showBlock(["auth","main"]);this.loadSettings()},insertTemplateIntoNode:function(e,t,i){i=i||false;var n="template-crm-ads-dlg-"+e;var o=n+"-"+this.provider.TYPE;var s=BX(o);if(!s){s=BX(n)}var r=BX.create("div");r.innerHTML=s.innerHTML;if(!i){t.innerHTML=""}var a=BX.convert.nodeListToArray(r.children);a.forEach((function(e){t.appendChild(e)}))},onResponse:function(e,t){if(!e.error){t.apply(this,[e.data])}},request:function(e,t,i,n){t.action=e;t.type=this.provider.TYPE;t.clientId=this.clientId;n=n||{};if(this.onRequest){this.onRequest.apply(this,[t,BX.delegate((function(e){this.onResponse(e,i)}),this)])}else{this.sendActionRequest(e,t,(function(e){this.onResponse(e,i)}),null,n)}},sendActionRequest:function(e,t,i,n,o){i=i||null;n=n||BX.proxy(this.showErrorPopup,this);t=t||{};var s=this;BX.ajax.runComponentAction(this.componentName,e,{mode:"class",signedParameters:this.signedParameters,data:t,analyticsLabel:o}).then((function(e){var t=e.data||{};if(t.error){n.apply(s,[t])}else if(i){i.apply(s,[t])}}),(function(){var e={error:true,text:""};n.apply(s,[e])}))},showErrorPopup:function(e){e=e||{};var t=e.text||this.mess.errorAction;var i=BX.PopupWindowManager.create("crm_ads_rtg_error",null,{autoHide:true,lightShadow:true,closeByEsc:true,overlay:{backgroundColor:"black",opacity:500},events:{onPopupClose:this.onErrorPopupClose.bind(this)}});i.setButtons([new BX.PopupWindowButton({text:this.mess.dlgBtnClose,events:{click:function(){this.popupWindow.close()}}})]);i.setContent('<span class="crm-ads-rtg-warning-popup-alert">'+t+"</span>");i.show()},showNewAudiencePopup:function(e,t){var i=BX.PopupWindowManager.create("crm_ads_rtg_new_audience",null,{width:500,autoHide:true,lightShadow:true,closeByEsc:true});var n=BX.create("input",{attrs:{type:"text",className:"crm-ads-rtg-input-input",value:t}});var o=BX.create("div",{attrs:{className:"crm-ads-rtg-input"},children:[BX.create("div",{attrs:{className:"crm-ads-rtg-input-label"},html:this.mess.newAudienceNameLabel}),n]});i.setContent(o);var s=this;i.setButtons([new BX.UI.Button({color:BX.UI.Button.Color.LINK,text:this.mess.dlgBtnCancel,events:{click:function(){i.close()}}}),new BX.UI.Button({color:BX.UI.Button.Color.SUCCESS,text:this.mess.dlgBtnCreate,events:{click:function(){var t=n.value;i.close();s.hideAddAudienceButton();s.request("addAudience",{accountId:e,name:t},BX.delegate((function(t){s.audienceId=t.id;s.loadSettingsAudiences(e)}),s))}}})]);i.show()},onErrorPopupClose:function(){if(this.clientSelector){this.clientSelector.enable();this.loader.forAccount(false);this.showAudienceLoadingState(false);this.showAddAudienceButton()}},setProfile:function(e){this.clientId=e&&e.CLIENT_ID?e.CLIENT_ID:null;this.provider.PROFILE=e;this.accountId=null;this.audienceId=null;if(this.containerNode){this.showBlockMain()}},loader:{init:function(e){this.caller=e},change:function(e,t,i){e.style.display=i?"":"none";if(t){t.disabled=!t.options.length==0||i?false:true}},forAccount:function(e){this.change(this.caller.uiNodes.accountLoader,this.caller.uiNodes.account,e)},forAudience:function(e){this.caller.uiNodes.audience.forEach((function(t){this.change(t.loader,t.node,e)}),this);if(this.caller.uiNodes.autoRemover.node){this.caller.uiNodes.autoRemover.node.style.display=e?"none":""}},forRegion:function(e){this.change(this.caller.uiNodes.regionLoader,this.caller.uiNodes.regionInput,e)}},loadSettings:function(){var e=this.provider.TYPE;var t=this.provider.IS_SUPPORT_ACCOUNT;var i=this.audienceLookalikeMode&&this.provider.IS_SUPPORT_LOOKALIKE_AUDIENCE;if(!this.provider.PROFILE){return}var n=BX.util.in_array(e,this.loaded);if(!n){this.loaded.push(e)}if(i&&this.uiNodes.regionInput){this.loadRegionsList()}if(this.uiNodes.account&&t){if(!n){var o=function(){this.loadSettingsAudiences(this.uiNodes.account.value)};BX.bind(this.uiNodes.account,"change",o.bind(this))}this.loadSettingsAccounts()}else{this.loadSettingsAudiences(null)}},loadSettingsAccounts:function(){this.hideAddAudienceButton();if(this.clientSelector){this.clientSelector.disable()}this.request("getAccounts",{},BX.delegate((function(e){if(this.clientSelector){this.clientSelector.enable()}var t=e.map((function(e){return{caption:e.name,value:e.id,selected:e.id==this.accountId}}),this);this.fillDropDownControl(this.uiNodes.account,t);this.loader.forAccount(false);if(t.length>0){var i=function(){BX.fireEvent(this.uiNodes.account,"change")};setTimeout(i.bind(this),150)}else{this.ShowErrorEmptyAudiences()}}),this))},loadSettingsAudiences:function(e){var t=this.isSupportLookalikeAudience();if(t&&this.isSupportCreateLookalikeFromSegments){return}this.showAudienceLoadingState(true);this.hideAddAudienceButton();var i={accountId:e||null,messageCode:this.messageCode};if(this.clientSelector){this.clientSelector.disable()}this.request("getAudiencesWithNormalizedStatus",i,BX.delegate((function(e){if(this.clientSelector){this.clientSelector.enable()}this.showAddAudienceButton();this.clearAudienceMenu();this.fillAudienceMenuFromResponseData(e);this.updateAudienceSelectorBtnByMenu(this.audienceMenu);this.hasAudiences=this.audienceMenu.getMenuItems().length>0;this.ShowErrorEmptyAudiences();this.showAudienceLoadingState(false)}),this))},showAudienceLoadingState:function(e){this.audienceSelectorBtn.setWaiting(e);this.audienceSelectorBtn.setDropdown(!e)},setAudienceSelectorBtnText:function(e){this.audienceSelectorBtn.setText(e)},updateAudienceSelectorBtnByMenu:function(e){const t=e.getMenuItems();const i=String(this.audienceId);let n=t.find((e=>String(e.id)===i));if(n!==undefined){this.setAudienceSelectorBtnText(n.text)}else{this.setAudienceSelectorBtnText(this.mess.chooseAudience)}},onAudienceSelectorBtnClick:function(){this.audienceMenu.toggle()},setSubmitAudienceData:function(e){this.uiNodes.audienceSelectorValue.value=String(e)},fillAudienceMenuFromResponseData:function(e){if(e.length===0){return}const t=this.removePlaceHolderAudienceFromResponseData(e);const i=[];t.forEach((e=>{const t=e=>{let t=i.find((t=>t.groupInfo.status===e.status&&t.groupInfo.normalizedStatus===e.normalizedStatus));if(t!==undefined){return t}t=i.find((t=>t.groupInfo.normalizedStatus===e.normalizedStatus&&["READY","PROCESSING"].includes(e.normalizedStatus)));return t};const n=t(e);if(n===undefined){i.push({groupInfo:{status:e.status,normalizedStatus:e.normalizedStatus,normalizedStatusMessage:e.normalizedStatusMessage,isEnabled:e.isEnabled},items:[e]})}else{n.items.push(e)}}));const n=i.sort(((e,t)=>{if(e.groupInfo.normalizedStatus==="READY"){return-1}if(t.groupInfo.normalizedStatus==="READY"){return 1}if(e.groupInfo.isEnabled||t.groupInfo.isEnabled){return t.groupInfo.isEnabled-e.groupInfo.isEnabled}if(e.groupInfo.normalizedStatus==="PROCESSING"){return-1}if(t.groupInfo.normalizedStatus==="PROCESSING"){return 1}return 0}));n.forEach((e=>{this.audienceMenu.addMenuItem({delimiter:true,text:e.groupInfo.normalizedStatusMessage});e.items.forEach((t=>this.audienceMenu.addMenuItem({id:String(t.id),text:t.name,value:t.id,disabled:!e.groupInfo.isEnabled,onclick:this.getClickAudienceMenuItemEventHandler(t)})))}))},removePlaceHolderAudienceFromResponseData:function(e){return e.filter((e=>Number(e.id)!==-1))},generateAudienceMenu:function(){return new BX.Main.Menu({maxHeight:340,bindOptions:{forceTop:true},bindElement:this.uiNodes.audienceSelectorBtn})},clearAudienceMenu:function(){this.audienceMenu=this.generateAudienceMenu()},getClickAudienceMenuItemEventHandler(e){return()=>{this.audienceSelectorBtn.setText(e.name);this.audienceMenu.close();this.setSubmitAudienceData(e.id)}},loadRegionsList:function(){this.loader.forRegion(true);this.fillDropDownControl(this.uiNodes.regionInput,[]);if(this.clientSelector){this.clientSelector.disable()}this.request("getRegions",{},BX.delegate((function(e){if(this.clientSelector){this.clientSelector.enable()}var t=e.map((function(e){return{caption:e.name,value:e.id,selected:this.audienceRegion?e.id==this.audienceRegion:e.isDefault}}),this);this.fillDropDownControl(this.uiNodes.regionInput,t);this.loader.forRegion(false)}),this))},ShowErrorEmptyAudiences:function(){if(this.uiNodes.errorNotFound){this.uiNodes.errorNotFound.style.display=this.hasAudiences?"none":""}},hideAddAudienceButton:function(){if(this.uiNodes.addAudienceBtn){BX.hide(this.uiNodes.addAudienceBtn)}},showAddAudienceButton:function(){if(this.uiNodes.addAudienceBtn){BX.show(this.uiNodes.addAudienceBtn)}},fillDropDownControl:function(e,t){t=t||[];e.innerHTML="";t.forEach((function(t){if(!t||!t.caption){return}var i=document.createElement("option");i.value=t.value;i.selected=!!t.selected;i.disabled=!!t.disabled;i.innerText=t.caption;e.appendChild(i)}))},isSupportLookalikeAudience:function(){return this.audienceLookalikeMode&&this.provider.IS_SUPPORT_LOOKALIKE_AUDIENCE}}}
//# sourceMappingURL=configurator.map.js